<!--
 * @Author: 宋绍华
 * @Date: 2024-11-12 14:58:02
 * @LastEditors: 宋绍华
 * @LastEditTime: 2024-12-20 16:38:34
 * @FilePath: \sr_system_manager_ui\src\views\project\components\MyProject\ReviewProcess.vue
 * @Description: 审核过程
-->
<template>
  <div mt-24px v-if="tableData.length > 0 && props.showNotices">
    <el-form label-width="77px" px-30px>
      <el-form-item label="审核记录">
        <el-table v-if="tableData.length > 0" border :data="tableData" style="width: 100%">
          <el-table-column prop="date" label="序号" width="48">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="createdTime" label="操作时间" />
          <el-table-column prop="typeName" label="动作" />
          <el-table-column prop="createdByName" label="操作人" />
          <el-table-column prop="date" label="操作结果">
            <template #default="scope">
              {{ scope.row.statusName }}
            </template>
          </el-table-column>
          <el-table-column prop="date" label="其他说明">
            <template #default="scope">
              <div>
                <div v-if="scope.row.remark">说明：{{ scope.row.remark }}</div>
                <div v-if="scope.row?.ossFileInfoDTOList?.length">附件：
                  <span @click="onPreview(attachment)" mr-10px v-for="attachment in scope.row?.ossFileInfoDTOList"
                    :key="attachment.id" style="color: #165DFF;white-space: nowrap;">
                    {{ `${attachment.name}.${attachment.suffix}；` }}
                  </span>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
    </el-form>

    <BusinessReview v-if="props.showNotices" ref="busRef" />
  </div>
  <div v-else>
    <el-empty description="暂无数据" />
  </div>
</template>

<script lang="ts" setup>
import BusinessReview from '../Details/BusinessReview.vue';
import { auditLogApi } from '@/api/resultsManagement';
import { ApprovalPageRespVO } from '@/types/resultsManagement';
const busRef = ref()
const props = defineProps({
  mode: {
    type: String as PropType<'add' | 'edit' | 'view'>,
    default: 'add'
  },
  projectId: {
    type: String,
    default: ''
  },
  showNotices: {
    type: Boolean,
    default: false
  }
})

const { proxy } = getCurrentInstance()

const tableData = ref<ApprovalPageRespVO[]>([])

const { runAsync: getRecordPage } = useRequest(auditLogApi, {
  manual: true,
  onSuccess: (res: ApprovalPageRespVO[]) => {
    tableData.value = res
  }
})

defineExpose({
  checkSheetFormValidate: () => {
    if (busRef.value.form.notices === '') {
      ElMessage.error('请填写审核意见')
      return
    }
    return busRef.value.form
  }
})

watch(
  () => props.mode,
  val => {
    if (val !== 'edit') {
      getRecordPage({ logId: props.projectId, type: 4, pageSize: 10000 })
    }
  },
  {
    immediate: true
  }
)

const onPreview = (item) => {
  proxy.$preview.open({
    src: item.url,
  })
}
</script>
